package com.design.proxy;

import java.lang.reflect.Proxy;

/**
 * @author cxx
 * @create 2020-04-21 11:29
 **/
public class ProxyUtil {

    public static <T> T proxy(T t){

        return (T) Proxy.newProxyInstance (t.getClass ().getClassLoader (),t.getClass ().getInterfaces (),(proxy,method,args)->{

            if (method.getDeclaringClass ().isAssignableFrom (Object.class)) {
                  return  method.invoke (t,args);
            }

            System.out.println ("前置处理");
            Object result = method.invoke (t, args);
            System.out.println ("后置处理");
            return result;
        });

    }

}
